package com.itqf.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * projectName: mybatis2103
 *
 * @author: 赵伟风
 * time: 2021/6/23 15:34
 * description:
 */
public class UseMyBatis {


    public static void main(String[] args) throws IOException {


        //1.读取核心配置文件
        /**
         * getResourceAsStream(classes下的路径)
         */
        InputStream stream = Resources.getResourceAsStream("mybatis_config.xml");

        //2.sqlSessionFactoryBuilder
        SqlSessionFactoryBuilder factoryBuilder = new SqlSessionFactoryBuilder();

        //3.sqlSessionFactory
        SqlSessionFactory sessionFactory = factoryBuilder.build(stream);

        //4.sqlsession
        SqlSession session = sessionFactory.openSession();

        //5.执行SQL语句
       // session.selectList("namespace.selectid值");
        List<Object> selectList = session.selectList("x.x.x.selectMenus");

        System.out.println("selectList = " + selectList);

        session.close();
    }

}
